<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseMedicalPerceptions.class.php';

Class MedicalPerceptions {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjMedicalPerceptions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMedicalPerceptions = new BaseMedicalPerceptions();
			$objMedicalPerceptions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objMedicalPerceptions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objMedicalPerceptions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objMedicalPerceptions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objMedicalPerceptions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objMedicalPerceptions->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objMedicalPerceptions->setNextVisitDate( ( true == isset( $row["next_visit_date"] ) ) ? $row["next_visit_date"] : 'NULL' );
			$objMedicalPerceptions->setMedicianName( ( true == isset( $row["medician_name"] ) ) ? $row["medician_name"] : 'NULL' );
			$objMedicalPerceptions->setQuantity( ( true == isset( $row["quantity"] ) ) ? $row["quantity"] : 'NULL' );
			$objMedicalPerceptions->setComapanyName( ( true == isset( $row["comapany_name"] ) ) ? $row["comapany_name"] : 'NULL' );
			$objMedicalPerceptions->setNote( ( true == isset( $row["note"] ) ) ? $row["note"] : 'NULL' );
			$objMedicalPerceptions->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objMedicalPerceptions->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjMedicalPerceptions, $objMedicalPerceptions );
		}
		return $arrobjMedicalPerceptions;
	}
	public function fetchAllMedicalPerceptions() {
		$result = $this->connection->RunQuery("SELECT * FROM MEDICAL_PERCEPTIONS");
		$arrobjMedicalPerceptions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMedicalPerceptions = new BaseMedicalPerceptions();
			$objMedicalPerceptions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objMedicalPerceptions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objMedicalPerceptions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objMedicalPerceptions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objMedicalPerceptions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objMedicalPerceptions->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objMedicalPerceptions->setNextVisitDate( ( true == isset( $row["next_visit_date"] ) ) ? $row["next_visit_date"] : 'NULL' );
			$objMedicalPerceptions->setMedicianName( ( true == isset( $row["medician_name"] ) ) ? $row["medician_name"] : 'NULL' );
			$objMedicalPerceptions->setQuantity( ( true == isset( $row["quantity"] ) ) ? $row["quantity"] : 'NULL' );
			$objMedicalPerceptions->setComapanyName( ( true == isset( $row["comapany_name"] ) ) ? $row["comapany_name"] : 'NULL' );
			$objMedicalPerceptions->setNote( ( true == isset( $row["note"] ) ) ? $row["note"] : 'NULL' );
			$objMedicalPerceptions->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objMedicalPerceptions->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjMedicalPerceptions, $objMedicalPerceptions);
		}
		return $arrobjMedicalPerceptions;
	}
	public function fetchAllMedicalPerceptionsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM MEDICAL_PERCEPTIONS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjMedicalPerceptions = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMedicalPerceptions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objMedicalPerceptions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objMedicalPerceptions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objMedicalPerceptions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objMedicalPerceptions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objMedicalPerceptions->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objMedicalPerceptions->setNextVisitDate( ( true == isset( $row["next_visit_date"] ) ) ? $row["next_visit_date"] : 'NULL' );
			$objMedicalPerceptions->setMedicianName( ( true == isset( $row["medician_name"] ) ) ? $row["medician_name"] : 'NULL' );
			$objMedicalPerceptions->setQuantity( ( true == isset( $row["quantity"] ) ) ? $row["quantity"] : 'NULL' );
			$objMedicalPerceptions->setComapanyName( ( true == isset( $row["comapany_name"] ) ) ? $row["comapany_name"] : 'NULL' );
			$objMedicalPerceptions->setNote( ( true == isset( $row["note"] ) ) ? $row["note"] : 'NULL' );
			$objMedicalPerceptions->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objMedicalPerceptions->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			array_push( $arrobjMedicalPerceptions, $objMedicalPerceptions );
		}
		return $arrobjMedicalPerceptions;
	}

	public function fetchMedicalPerceptionsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM MEDICAL_PERCEPTIONS WHERE id = " . $intId );
			$objMedicalPerceptions = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objMedicalPerceptions = new BaseMedicalPerceptions();
			$objMedicalPerceptions->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objMedicalPerceptions->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objMedicalPerceptions->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objMedicalPerceptions->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objMedicalPerceptions->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objMedicalPerceptions->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objMedicalPerceptions->setNextVisitDate( ( true == isset( $row["next_visit_date"] ) ) ? $row["next_visit_date"] : 'NULL' );
			$objMedicalPerceptions->setMedicianName( ( true == isset( $row["medician_name"] ) ) ? $row["medician_name"] : 'NULL' );
			$objMedicalPerceptions->setQuantity( ( true == isset( $row["quantity"] ) ) ? $row["quantity"] : 'NULL' );
			$objMedicalPerceptions->setComapanyName( ( true == isset( $row["comapany_name"] ) ) ? $row["comapany_name"] : 'NULL' );
			$objMedicalPerceptions->setNote( ( true == isset( $row["note"] ) ) ? $row["note"] : 'NULL' );
			$objMedicalPerceptions->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objMedicalPerceptions->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
		}
		return $objMedicalPerceptions;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from medical_perceptions order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endMedicalPerceptions(){
		$this->connection->CloseMysql();
	}

}